<?php

namespace  Ekadmin\Controller;
use \Think\Controller;
use Think\Page;

class FlashController extends CommonController
{

        public  function index()
        {

            $where['uniacid'] = $this->uniacid;

            $obj = M('flash');
            $count = $obj->where($where)->count();
            $page = new Page($count);
            $list = $obj->where($where)->limit($page->firstRow.','.$page->listRows)->select();                        if($list){                                for($i=0;$i<count($list);$i++){                    switch($list[$i]["type"]){                        case 1:                            $list[$i]["type"]="首页";                            break;                        case 2:                            $list[$i]["type"]="申请群主广告";                            break;                        case 3:                            $list[$i]["type"]="待添加";                            break;                                                }                }                            }
            $this->assign('page',$page->show());
            $this->assign('count',$count);
            $this->assign('list',$list);
            $this->display();
        }


        public function  edit()
        {
            $this->assign('data',M('flash')->where("id=".I("id")." and uniacid=".$this->uniacid)->find());
            $this->display('form');
        }


        public function add()
        {
            $this->display('form');

        }


    public function del()
    {
        if(IS_POST){
            $param = I('id');

            if(is_array($param)){
                $map['id'] = array('in',$param);
            }else{
                $map['id'] = $param;
            }

            $map['uniacid'] = $this->uniacid;
            
            M('flash')->where($map)->delete();

            ajax_return(0,'删除成功');
        }
    }


    public function update()
    {
        if(IS_POST){
            $param = I('post.');
            if(!$param['thumb']){
                ajax_return(1,'请上传图片');
            }
            $param['status'] = $param['status'] == 'on'?1:2;
            
            

            $obj = M('flash');
            if($param['id']){
                $obj->save($param);
            }else{
                $param['addtime'] = time();
                $param['uniacid'] = $this->uniacid;
                $obj->add($param);
            }

            ajax_return(0,'保存成功',U('index'));
        }
    }





}